package studio.raptor.hub.in.server;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.apache.http.client.HttpClient;
import studio.raptor.hub.in.ServerProxy;

import java.util.List;

/**
 * Created by liuyong8 on 2017/7/25.
 */
public class SoCommitOrderProxy extends ServerProxy{
//    {
//        "coId": 1000000000013845
//    }
    private static final String REQ_MESSAGE = "{\"coId\": %s}";

    public SoCommitOrderProxy(HttpClient httpClient) {
        super(httpClient);
    }

    @Override
    protected String handleResponse(String response) {
        DocumentContext sc = JsonPath.parse(response);
        Object object = sc.read("$.resultObject");
        String result = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
        if (result.startsWith("{")) {
            result = result.substring(1,result.length()-1);
        }
        return result;
    }

    @Override
    protected String getMessage(Long... params) {
        String message = String.format(REQ_MESSAGE,params);
        return  message;
    }
}
